home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / quicktimeintro / wiredsprites / common files / comframework.c next >
Encoding:
Text File  |  2000-10-06  |  54.0 KB  |  1,968 lines

  1. //////////
  2. //
  3. //    File:        ComFramework.c
  4. //
  5. //    Contains:    Code for the QuickTime sample code framework that is common to both Macintosh and Windows.
  6. //
  7. //    Written by:    Tim Monroe
  8. //                Based on the QTShell code written by Tim Monroe, which in turn was based on the MovieShell
  9. //                code written by Kent Sandvik (Apple DTS). This current version is now very far removed from
  10. //                MovieShell.
  11. //
  12. //    Copyright:    © 1999 by Apple Computer, Inc., all rights reserved.
  13. //
  14. //    Change History (most recent first):
  15. //       
  16. //       <16>         03/15/00    rtm        modified QTFrame_SaveAsMovieFile to create a single-fork, self-contained,
  17. //                                    interleaved, Fast Start movie
  18. //       <15>         03/02/00    rtm        made changes to get things running under CarbonLib
  19. //       <14>         02/16/00    rtm        added QTFrame_GetWindowPtrFromWindowReference
  20. //       <13>         01/19/00    rtm        revised QTFrame_IsAppWindow (dialog windows no longer count as application
  21. //                                    windows); added QTFrame_BuildFileTypeList and QTFrame_AddComponentFileTypes
  22. //                                    to avoid calling GetMovieImporterForDataRef in QTFrame_FilterFiles; removed
  23. //                                    the hard-coded file types
  24. //       <12>         01/14/00    rtm        added support for graphics files, using graphics importers
  25. //       <11>         12/28/99    rtm        added QTFrame_ConvertMacToWinRect and QTFrame_ConvertWinToMacRect
  26. //       <10>         12/21/99    rtm        hard-coded some file types into QTFrame_FilterFiles; if we let QuickTime
  27. //                                    to do all the testing (using GetMovieImporterForDataRef), it takes too long
  28. //       <9>         12/17/99    rtm        added some code to QTFrame_SetMenuItemState to work around a problem that
  29. //                                    appears under MacOS 8.5.1 (as far as I can tell...)
  30. //       <8>         12/16/99    rtm        added QTApp_HandleMenu calls to _HandleFileMenuItem and _HandleEditMenuItem
  31. //                                    to allow the application-specific code to intercept menu item selections;
  32. //                                    added QTFrame_FilterFiles
  33. //       <7>         12/15/99    rtm        added QTApp_Idle call to QTFrame_IdleMovieWindows
  34. //       <6>         12/11/99    rtm        added GetMenuState call to Windows portion of QTFrame_SetMenuItemLabel;
  35. //                                    tweaked _SizeWindowToMovie to guard against NULL movie and/or controller
  36. //       <5>         11/30/99    rtm        added QTFrame_CloseMovieWindows
  37. //       <4>         11/27/99    rtm        added QTFrame_GetFileFilterUPP
  38. //       <3>         11/17/99    rtm        finished support for Navigation Services; added QTFrame_IdleMovieWindows
  39. //       <2>         11/16/99    rtm        begun support for Navigation Services
  40. //       <1>         11/05/99    rtm        first file
  41. //
  42. //    This file contains several kinds of functions: (1) functions that use completely cross-platform APIs and
  43. //    which therefore can be compiled and run for both Mac and Windows platforms with no changes whatsoever (a
  44. //    good example of this is QTFrame_SaveAsMovieFile); (2) functions that are substantially the same on both
  45. //    platforms but which require several short platform-dependent #ifdef TARGET_OS_ blocks (a good example of
  46. //    this is QTFrame_AdjustMenus); (3) functions that retrieve data from framework-specific data structures (a
  47. //    good example of this is QTFrame_GetWindowObjectFromWindow); (4) functions that provide a platform-neutral
  48. //    interface to platform-specific operations (a good example of this is QTFrame_Beep). In a nutshell, this
  49. //    file attempts to provide platform-independent services to its callers, typically functions in the files
  50. //    MacFramework.c, WinFramework.c, and ComApplication.c.
  51. //
  52. //    In general, you should not need to modify this file. Your application-specific code should usually be put
  53. //    into the file ComApplication.c.
  54. //
  55. //////////
  56.  
  57. //////////
  58. //
  59. // header files
  60. //
  61. //////////
  62.  
  63. #include "ComFramework.h"
  64.  
  65.  
  66. //////////
  67. //
  68. // global variables
  69. //
  70. //////////
  71.  
  72. Rect                    gMCResizeBounds;                        // maximum size for any movie window
  73. OSType                     *gValidFileTypes = NULL;                // the list of file types that our application can open
  74.  
  75. #if TARGET_OS_WIN32
  76. extern HWND                ghWnd;
  77. extern HWND                ghWndMDIClient;
  78. extern BOOL                gWeAreSizingWindow;
  79. #endif
  80.  
  81. #if TARGET_OS_MAC
  82. extern Str255            gAppName;
  83. void                    QTFrame_HandleEvent (EventRecord *theEvent);
  84. #endif
  85.  
  86.  
  87. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  88. //
  89. // Menu-handling functions.
  90. //
  91. // Use these functions to handle items in the File and Edit menus.
  92. //
  93. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  94.  
  95. //////////
  96. //
  97. // QTFrame_HandleFileMenuItem
  98. // Handle the specified File menu item.
  99. //
  100. //////////
  101.  
  102. void QTFrame_HandleFileMenuItem (WindowReference theWindow, UInt16 theMenuItem)
  103. {
  104.     // give the application-specific code a chance to intercept the menu item selection
  105.     if (QTApp_HandleMenu(theMenuItem))
  106.         return;
  107.         
  108.     switch (theMenuItem) {
  109.     
  110.         case IDM_FILENEW:
  111.             QTFrame_CreateNewMovie();
  112.             break;
  113.  
  114.         case IDM_FILEOPEN:
  115.             QTFrame_OpenMovieInWindow(NULL, NULL);
  116.             break;
  117.  
  118.         case IDM_FILECLOSE:
  119.             QTFrame_DestroyMovieWindow(theWindow);
  120.             break;
  121.  
  122.         case IDM_FILESAVE:
  123.             QTFrame_UpdateMovieFile(theWindow);
  124.             break;
  125.  
  126.         case IDM_FILESAVEAS:
  127.             QTFrame_SaveAsMovieFile(theWindow);
  128.             break;
  129.             
  130.         case IDM_EXIT:
  131.             QTFrame_QuitFramework();
  132.             break;
  133.  
  134.         default:
  135.             break;
  136.     } // switch (theMenuItem)
  137.     
  138. }
  139.  
  140.  
  141. //////////
  142. //
  143. // QTFrame_HandleEditMenuItem
  144. // Perform the specified edit operation on the specified window.
  145. //
  146. //////////
  147.  
  148. void QTFrame_HandleEditMenuItem (WindowReference theWindow, UInt16 theMenuItem)
  149. {
  150.     WindowObject        myWindowObject = NULL;
  151.     MovieController     myMC = NULL;
  152.     Movie                 myEditMovie = NULL;                // the movie created by some editing operations
  153.     
  154.     // give the application-specific code a chance to intercept the menu item selection
  155.     if (QTApp_HandleMenu(theMenuItem))
  156.         return;
  157.     
  158.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  159.     myMC = QTFrame_GetMCFromWindow(theWindow);
  160.     
  161.     // make sure we have a valid movie controller and a valid window object
  162.     if ((myMC == NULL) || (myWindowObject == NULL))
  163.         return;
  164.  
  165.     switch (theMenuItem) {
  166.     
  167.         case IDM_EDITUNDO:
  168.             MCUndo(myMC);
  169.             (**myWindowObject).fIsDirty = true;
  170.             break;
  171.  
  172.         case IDM_EDITCUT:
  173.             myEditMovie = MCCut(myMC);
  174.             (**myWindowObject).fIsDirty = true;
  175.             break;
  176.  
  177.         case IDM_EDITCOPY:
  178.             myEditMovie = MCCopy(myMC);
  179.             break;
  180.  
  181.         case IDM_EDITPASTE:
  182.             MCPaste(myMC, NULL);
  183.             (**myWindowObject).fIsDirty = true;
  184.             break;
  185.  
  186.         case IDM_EDITCLEAR:
  187.             MCClear(myMC);
  188.             (**myWindowObject).fIsDirty = true;
  189.             break;
  190.             
  191.         case IDM_EDITSELECTALL:
  192.             QTUtils_SelectAllMovie(myMC);
  193.             break;
  194.  
  195.         case IDM_EDITSELECTNONE:
  196.             QTUtils_SelectNoneMovie(myMC);
  197.             break;
  198.  
  199.         default:
  200.             break;
  201.     } // switch (theMenuItem)
  202.     
  203.     // place any cut or copied movie segment onto the scrap
  204.     if (myEditMovie != NULL) {
  205.         PutMovieOnScrap(myEditMovie, 0L);
  206.         DisposeMovie(myEditMovie);
  207.     }
  208. }
  209.  
  210.  
  211. //////////
  212. //
  213. // QTFrame_AdjustMenus 
  214. // Adjust the application's menus.
  215. //
  216. // On Windows, the theWindow parameter is a handle to the active MDI *child* window, if any.
  217. // On Mac, the theWindow parameter is a pointer to the frontmost window, if any.
  218. //
  219. //////////
  220.  
  221. int QTFrame_AdjustMenus (WindowReference theWindow, MenuReference theMenu)
  222. {
  223. #if TARGET_OS_MAC
  224. #pragma unused(theMenu)
  225. #endif
  226.  
  227.     WindowObject        myWindowObject = NULL; 
  228.     MovieController     myMC = NULL;
  229.     MenuReference        myMenu = NULL;
  230.     
  231. #if TARGET_OS_WIN32
  232.     myMenu = theMenu;
  233. #endif
  234.  
  235.     if (theWindow != NULL)
  236.         myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  237.  
  238.     if (myWindowObject != NULL)
  239.         myMC = (**myWindowObject).fController;
  240.  
  241.     //////////
  242.     //
  243.     // configure the Edit menu
  244.     //
  245.     //////////
  246.     
  247. #if TARGET_OS_MAC
  248.     myMenu = GetMenuHandle(kEditMenuResID);
  249. #endif
  250.     if (myMC != NULL) {
  251.         long    myFlags;
  252.         
  253.         MCGetControllerInfo(myMC, &myFlags);
  254.     
  255.         QTFrame_SetMenuItemState(myMenu, IDM_EDITUNDO, myFlags & mcInfoUndoAvailable ? kEnableMenuItem : kDisableMenuItem);
  256.         QTFrame_SetMenuItemState(myMenu, IDM_EDITCUT, myFlags & mcInfoCutAvailable ? kEnableMenuItem : kDisableMenuItem);
  257.         QTFrame_SetMenuItemState(myMenu, IDM_EDITCOPY, myFlags & mcInfoCopyAvailable ? kEnableMenuItem : kDisableMenuItem);
  258.         QTFrame_SetMenuItemState(myMenu, IDM_EDITPASTE, myFlags & mcInfoPasteAvailable ? kEnableMenuItem : kDisableMenuItem);
  259.         QTFrame_SetMenuItemState(myMenu, IDM_EDITCLEAR, myFlags & mcInfoClearAvailable ? kEnableMenuItem : kDisableMenuItem);
  260.         QTFrame_SetMenuItemState(myMenu, IDM_EDITSELECTALL, myFlags & mcInfoEditingEnabled ? kEnableMenuItem : kDisableMenuItem);
  261.         QTFrame_SetMenuItemState(myMenu, IDM_EDITSELECTNONE, myFlags & mcInfoEditingEnabled ? kEnableMenuItem : kDisableMenuItem);
  262.     } else {
  263.         QTFrame_SetMenuItemState(myMenu, IDM_EDITUNDO, kDisableMenuItem);
  264.         QTFrame_SetMenuItemState(myMenu, IDM_EDITCUT, kDisableMenuItem);
  265.         QTFrame_SetMenuItemState(myMenu, IDM_EDITCOPY, kDisableMenuItem);
  266.         QTFrame_SetMenuItemState(myMenu, IDM_EDITPASTE, kDisableMenuItem);
  267.         QTFrame_SetMenuItemState(myMenu, IDM_EDITCLEAR, kDisableMenuItem);
  268.         QTFrame_SetMenuItemState(myMenu, IDM_EDITSELECTALL, kDisableMenuItem);
  269.         QTFrame_SetMenuItemState(myMenu, IDM_EDITSELECTNONE, kDisableMenuItem);
  270.     }
  271.  
  272.     //////////
  273.     //
  274.     // configure the File menu
  275.     //
  276.     //////////
  277.     
  278. #if TARGET_OS_MAC
  279.     myMenu = GetMenuHandle(kFileMenuResID);
  280. #endif
  281.     if (theWindow != NULL) {                // there is a window open
  282.         // handle the Close command
  283.         QTFrame_SetMenuItemState(myMenu, IDM_FILECLOSE, kEnableMenuItem);
  284.         
  285.         // handle the Save As and Save commands
  286.         if (myWindowObject != NULL) {
  287.             QTFrame_SetMenuItemState(myMenu, IDM_FILESAVEAS, kEnableMenuItem);
  288.             QTFrame_SetMenuItemState(myMenu, IDM_FILESAVE, (**myWindowObject).fIsDirty ? kEnableMenuItem : kDisableMenuItem);
  289.         } else {
  290.             QTFrame_SetMenuItemState(myMenu, IDM_FILESAVEAS, kDisableMenuItem);
  291.             QTFrame_SetMenuItemState(myMenu, IDM_FILESAVE, kDisableMenuItem);
  292.         }
  293.     
  294.     } else {                                // there is no window open    
  295.         QTFrame_SetMenuItemState(myMenu, IDM_FILESAVE, kDisableMenuItem);
  296.         QTFrame_SetMenuItemState(myMenu, IDM_FILESAVEAS, kDisableMenuItem);
  297.         QTFrame_SetMenuItemState(myMenu, IDM_FILECLOSE, kDisableMenuItem);        
  298.     }
  299.  
  300.     // adjust any application-specific menus
  301.     QTApp_AdjustMenus(theWindow, theMenu);
  302.  
  303.     return(0);
  304. }
  305.  
  306.  
  307. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  308. //
  309. // Movie-handling functions.
  310. //
  311. // Use these functions to create new movies, open existing movies, save movies, and so forth.
  312. //
  313. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  314.  
  315. //////////
  316. //
  317. // QTFrame_CreateNewMovie
  318. // Create a new movie in a window; returns true if successful.
  319. //
  320. // NOTE: There are several user interface issues that are blissfully ignored by this routine,
  321. // principally the preferred names and the on-screen locations of the new windows. 
  322. //
  323. //////////
  324.  
  325. Boolean QTFrame_CreateNewMovie (void)
  326. {
  327.     Movie                myMovie = NULL;
  328.     FSSpec                myFSSpec;
  329.     StringPtr             myName = QTUtils_ConvertCToPascalString(kNewMovieName);
  330.     
  331.     myMovie = NewMovie(newMovieActive);
  332.     if (myMovie == NULL)
  333.         return(false);
  334.     
  335.     // create a default FSSpec
  336.     FSMakeFSSpec(0, 0L, myName, &myFSSpec);
  337.     
  338.     free(myName);
  339.     
  340.     return(QTFrame_OpenMovieInWindow(myMovie, &myFSSpec));
  341. }
  342.  
  343.  
  344. //////////
  345. //
  346. // QTFrame_OpenMovieInWindow
  347. // Open a movie in a new movie window; return true if successful.
  348. //
  349. // This function is called from several places in our framework. The following combinations are possible:
  350. //    * theMovie == NULL, theFSSpec == NULL: no movie, no file; elicit a movie file from user and open it
  351. //    * theMovie != NULL, theFSSpec == NULL: new movie, no file (yet)
  352. //    * theMovie == NULL, theFSSpec != NULL: no movie, but we have an FSSpec; so just open the specified movie file
  353. //    * theMovie != NULL, theFSSpec != NULL: new movie, theFSSpec contains (at least) the movie name
  354. //
  355. //////////
  356.  
  357. Boolean QTFrame_OpenMovieInWindow (Movie theMovie, FSSpec *theFSSpec)
  358. {
  359.     WindowObject            myWindowObject = NULL;
  360.     Movie                    myMovie = NULL;
  361.     MovieController            myMC = NULL;
  362.     GraphicsImportComponent    myImporter = NULL;
  363.     WindowReference            myWindow = NULL;
  364.     FSSpec                    myFSSpec;
  365.     short                    myRefNum = kInvalidFileRefNum;
  366.     short                    myResID = 0;
  367.     OSType                     myTypeList[] = {kQTFileTypeMovie, kQTFileTypeQuickTimeImage};
  368.     short                    myNumTypes = 2;
  369.     GrafPtr                    mySavedPort;
  370.     Rect                    myRect = {0, 0, 0, 0};
  371.     Point                    myPoint;
  372.     QTFrameFileFilterUPP    myFileFilterUPP = NULL;
  373.     OSErr                    myErr = noErr;
  374.  
  375. #if TARGET_OS_MAC
  376.     myNumTypes = 0;
  377. #endif
  378.  
  379.     // get the current port; we may need to restore it if we cannot successfully create a new window
  380.     GetPort(&mySavedPort);
  381.     
  382.     // if we got neither a movie nor an FSSpec passed in, prompt the user for a movie file
  383.     if ((theMovie == NULL) && (theFSSpec == NULL)) {
  384.         myFileFilterUPP = QTFrame_GetFileFilterUPP((ProcPtr)QTFrame_FilterFiles);
  385.     
  386.         myErr = QTFrame_GetOneFileWithPreview(myNumTypes, (QTFrameTypeListPtr)myTypeList, &myFSSpec, myFileFilterUPP);
  387.     
  388.         if (myFileFilterUPP != NULL)
  389.             DisposeNavObjectFilterUPP(myFileFilterUPP);
  390.  
  391.         if (myErr != noErr)
  392.             goto bail;
  393.     }
  394.     
  395.     // if we got an FSSpec passed in, copy it into myFSSpec
  396.     if (theFSSpec != NULL) {
  397.         FSMakeFSSpec(theFSSpec->vRefNum, theFSSpec->parID, theFSSpec->name, &myFSSpec);        
  398.     }
  399.  
  400.     // if we got no movie passed in, read one from the specified file
  401.     if (theMovie == NULL) {
  402.         // see if the FSSpec picks out an image file; if so, skip the movie-opening code
  403. // UNCOMMENT THESE LINES WHEN THE OS X PDF IMPORTER STOPS THINKING IT CAN OPEN MOVIE FILES (RADAR 2443744)
  404. //        myErr = GetGraphicsImporterForFile(&myFSSpec, &myImporter);
  405. //        if (myImporter != NULL)
  406. //            goto gotImageFile;
  407.             
  408.         // ideally, we'd like read and write permission, but we'll settle for read-only permission
  409.         myErr = OpenMovieFile(&myFSSpec, &myRefNum, fsRdWrPerm);
  410.         if (myErr != noErr)
  411.             myErr = OpenMovieFile(&myFSSpec, &myRefNum, fsRdPerm);
  412.  
  413.         // if we couldn't open the file with even just read-only permission, bail....
  414.         if (myErr != noErr)
  415.             goto bail;
  416.  
  417.         // now fetch the first movie from the file
  418.         myResID = 0;
  419.         myErr = NewMovieFromFile(&myMovie, myRefNum, &myResID, NULL, newMovieActive, NULL);
  420.         if (myErr != noErr)
  421.             goto bail;
  422.     } else {
  423.         myMovie = theMovie;
  424.     }
  425.  
  426.     //////////
  427.     //
  428.     // at this point, myMovie is an open movie, but myFSSpec may or may not be a valid FSSpec
  429.     //
  430.     //////////
  431.     
  432.     // set the default progress procedure for the movie
  433.     SetMovieProgressProc(myMovie, (MovieProgressUPP)-1, 0);
  434.         
  435. gotImageFile:
  436.     // create a new window to display the movie in
  437.     myWindow = QTFrame_CreateMovieWindow();
  438.     if (myWindow == NULL)
  439.         goto bail;
  440.     
  441.     myWindowObject = QTFrame_GetWindowObjectFromWindow(myWindow);
  442.     if (myWindowObject == NULL)
  443.         goto bail;
  444.     
  445.     // set the window title
  446.     QTFrame_SetWindowTitleFromFSSpec(myWindow, &myFSSpec, true);
  447.  
  448.     // make sure the movie or image file uses the window GWorld
  449.     if (myMovie != NULL)
  450.         SetMovieGWorld(myMovie, (CGrafPtr)QTFrame_GetPortFromWindowReference(myWindow), NULL);
  451.  
  452.     if (myImporter != NULL)
  453.         GraphicsImportSetGWorld(myImporter, (CGrafPtr)QTFrame_GetPortFromWindowReference(myWindow), NULL);
  454.  
  455.     // create and configure the movie controller
  456.     myMC = QTFrame_SetupController(myMovie, myWindow, true);
  457.         
  458.     // store movie info in the window record
  459.     (**myWindowObject).fMovie = myMovie;
  460.     (**myWindowObject).fController = myMC;
  461.     (**myWindowObject).fGraphicsImporter = myImporter;
  462.     (**myWindowObject).fFileResID = myResID;
  463.     (**myWindowObject).fFileRefNum = myRefNum;
  464.     (**myWindowObject).fCanResizeWindow = true;
  465.     (**myWindowObject).fIsDirty = false;
  466.     (**myWindowObject).fIsQTVRMovie = QTUtils_IsQTVRMovie(myMovie);
  467.     (**myWindowObject).fInstance = NULL;
  468.     (**myWindowObject).fAppData = NULL;
  469.     (**myWindowObject).fFileFSSpec = myFSSpec;
  470.     
  471.     // do any application-specific window object initialization
  472.     QTApp_SetupWindowObject(myWindowObject);
  473.     
  474.     // size the window to fit the movie and controller
  475.     QTFrame_SizeWindowToMovie(myWindowObject);
  476.  
  477.     // set the movie's play hints to allow dynamic resizing
  478.     SetMoviePlayHints(myMovie, hintsAllowDynamicResize, hintsAllowDynamicResize);
  479.  
  480.     // set the movie's position, if it has a 'WLOC' user data atom
  481.     myErr = QTUtils_GetWindowPositionFromFile(myMovie, &myPoint);
  482.  
  483.     // show the window
  484. #if TARGET_OS_MAC
  485.     MoveWindow(myWindow, myPoint.h, myPoint.v, false);
  486.     ShowWindow(myWindow);
  487.     SelectWindow(myWindow);                                // make it front-most, since it's just been created
  488.     InvalWindowRect(myWindow, GetWindowPortBounds(myWindow, &myRect));
  489. #endif
  490. #if TARGET_OS_WIN32
  491.     SetWindowPos(myWindow, 0, myPoint.h, myPoint.v, 0, 0, SWP_NOZORDER | SWP_NOSIZE);
  492.     ShowWindow(myWindow, SW_SHOW);
  493.     UpdateWindow(myWindow);
  494. #endif
  495.  
  496.     // if the movie is a streamed movie, then start it playing immediately
  497.     if (QTUtils_IsStreamedMovie(myMovie))
  498.         MCDoAction(myMC, mcActionPrerollAndPlay, (void *)GetMoviePreferredRate(myMovie));
  499.         
  500.     return(true);
  501.     
  502. bail:
  503.     if (myWindow != NULL)
  504. #if TARGET_OS_MAC
  505.         DisposeWindow(myWindow);
  506. #endif
  507. #if TARGET_OS_WIN32
  508.         SendMessage(ghWndMDIClient, WM_MDIDESTROY, (WPARAM)myWindow, 0L);
  509. #endif
  510.         
  511.     if (myMC != NULL)
  512.         DisposeMovieController(myMC);
  513.         
  514.     if (myMovie != NULL)
  515.         DisposeMovie(myMovie);
  516.         
  517.     if (myRefNum != 0)
  518.         CloseMovieFile(myRefNum);
  519.  
  520.     if (myImporter != NULL)
  521.         CloseComponent(myImporter);
  522.         
  523.     MacSetPort(mySavedPort);    // restore the port that was active when this function was called
  524.  
  525.     return(false);
  526. }
  527.  
  528.  
  529. //////////
  530. //
  531. // QTFrame_SetupController
  532. // Create and configure the movie controller.
  533. //
  534. //////////
  535.  
  536. MovieController QTFrame_SetupController (Movie theMovie, WindowReference theWindow, Boolean theMoveWindow)
  537. {
  538. #if TARGET_OS_WIN32
  539. #pragma unused(theMoveWindow)
  540. #endif
  541.  
  542.     MovieController            myMC = NULL;
  543.     Rect                    myRect;
  544.     WindowObject            myWindowObject = NULL;
  545.     GrafPtr                    mySavedPort;
  546.  
  547.     if ((theMovie == NULL) || (theWindow == NULL))
  548.         return(NULL);
  549.         
  550.     // get our window specific data
  551.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  552.     if (myWindowObject == NULL)
  553.         return(NULL);
  554.         
  555.     GetPort(&mySavedPort);
  556.     MacSetPort(QTFrame_GetPortFromWindowReference(theWindow));
  557.     
  558.     // resize the movie bounding rect and offset to 0,0
  559.     GetMovieBox(theMovie, &myRect);
  560.     MacOffsetRect(&myRect, -myRect.left, -myRect.top);
  561.     SetMovieBox(theMovie, &myRect);
  562.     AlignWindow(QTFrame_GetWindowFromWindowReference(theWindow), false, &myRect, NULL);
  563.  
  564.     // create the movie controller
  565.     myMC = NewMovieController(theMovie, &myRect, mcTopLeftMovie);
  566.     if (myMC == NULL)
  567.         return(NULL);
  568.         
  569.     // enable the default movie controller editing
  570.     MCEnableEditing(myMC, true);
  571.         
  572.     // suppress movie badge
  573.     MCDoAction(myMC, mcActionSetUseBadge, (void *)false);
  574.  
  575.     // set the initial looping state of the movie
  576.     QTUtils_SetLoopingStateFromFile(theMovie, myMC);
  577.     
  578.     // install an action filter that does any application-specific movie controller action processing
  579.     MCSetActionFilterWithRefCon(myMC, NewMCActionFilterWithRefConProc(QTApp_MCActionFilterProc), (long)myWindowObject);
  580.  
  581.     // add grow box for the movie controller
  582.     if ((**myWindowObject).fCanResizeWindow) {
  583. #if TARGET_OS_WIN32
  584.         RECT                myRect;
  585.  
  586.         GetWindowRect(GetDesktopWindow(), &myRect);
  587.         OffsetRect(&myRect, -myRect.left, -myRect.top);
  588.         QTFrame_ConvertWinToMacRect(&myRect, &gMCResizeBounds);
  589. #endif
  590. #if TARGET_OS_MAC
  591.         GetRegionBounds(GetGrayRgn(), &gMCResizeBounds);
  592. #endif
  593.  
  594.         MCDoAction(myMC, mcActionSetGrowBoxBounds, &gMCResizeBounds);
  595.     }
  596.     
  597. #if TARGET_OS_MAC
  598.     if (theMoveWindow)
  599.         MoveWindow(theWindow, kDefaultWindowX, kDefaultWindowY, false);
  600. #endif
  601.  
  602.     MacSetPort(mySavedPort);
  603.  
  604.     // add any application-specific controller functionality
  605.     QTApp_SetupController(myMC);
  606.         
  607.     return(myMC);
  608. }
  609.  
  610.  
  611. //////////
  612. //
  613. // QTFrame_SaveAsMovieFile
  614. // Save the movie in the specified window under a new name.
  615. //
  616. // Human interface guidelines for "Save As..." dictate that, if the user selects a new file name
  617. // for the current movie, then that new file shall become the active one. This means that we need
  618. // to close the current movie file and open the new one.
  619. //
  620. //////////
  621.  
  622. OSErr QTFrame_SaveAsMovieFile (WindowReference theWindow)
  623. {
  624.     WindowObject        myWindowObject = NULL;
  625.     Movie                 myMovie = NULL;
  626.     FSSpec                myFile;
  627.     Boolean                myIsSelected = false;
  628.     Boolean                myIsReplacing = false;    
  629.     StringPtr             myPrompt = QTUtils_ConvertCToPascalString(kSavePrompt);
  630.     StringPtr             myFileName = QTUtils_ConvertCToPascalString(kSaveMovieFileName);
  631.     OSErr                myErr = paramErr;
  632.     
  633.     // get the window object associated with the specified window
  634.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  635.     if (myWindowObject == NULL)
  636.         goto bail;
  637.         
  638.     myMovie = (**myWindowObject).fMovie;
  639.     if (myMovie == NULL)
  640.         goto bail;
  641.         
  642.     QTFrame_PutFile(myPrompt, myFileName, &myFile, &myIsSelected, &myIsReplacing);
  643.     if (myIsSelected) {
  644.         Movie            myNewMovie = NULL;
  645.         MovieController    myMC = NULL;
  646.         short            myRefNum = kInvalidFileRefNum;
  647.         short            myResID = movieInDataForkResID;
  648.         
  649.         //////////
  650.         //
  651.         // we have a valid FSSpec for the new movie file; now we want to flatten the existing
  652.         // movie into the new movie file, then open the new movie file and read the movie out
  653.         // of it; then we need to swap the window object data
  654.         //
  655.         //////////
  656.         
  657.         // delete any existing file of that name
  658.         if (myIsReplacing) {
  659.             myErr = DeleteMovieFile(&myFile);
  660.             if (myErr != noErr)
  661.                 goto bail;
  662.         }
  663.         
  664.         myNewMovie = FlattenMovieData(    myMovie,
  665.                                         flattenAddMovieToDataFork | flattenForceMovieResourceBeforeMovieData,
  666.                                         &myFile,
  667.                                         sigMoviePlayer,
  668.                                         smSystemScript,
  669.                                         createMovieFileDeleteCurFile | createMovieFileDontCreateResFile);
  670.         myErr = GetMoviesError();
  671.         if ((myNewMovie == NULL) || (myErr != noErr))
  672.             goto bail;
  673.  
  674.         // FlattenMovieData creates a new movie file and returns the movie to us; but it doesn't
  675.         // return the file reference number or the movie resource ID, which we want to have; so
  676.         // we will dump the movie returned by FlattenMovieData and open the movie file ourselves
  677.         DisposeMovie(myNewMovie);
  678.  
  679.         myErr = OpenMovieFile(&myFile, &myRefNum, fsRdWrPerm);
  680.         if (myErr != noErr)
  681.             goto bail;
  682.  
  683.         // get the new movie from the file
  684.         myErr = NewMovieFromFile(&myNewMovie, myRefNum, &myResID, NULL, newMovieActive, NULL);        
  685.         if (myErr != noErr)
  686.             goto bail;
  687.  
  688.         // create a new movie controller
  689.         myMC = QTFrame_SetupController(myNewMovie, theWindow, false);
  690.         
  691.         //////////
  692.         //
  693.         // if we got to here, we've successfully created a new movie file, and NewMovieFromFile has
  694.         // returned the new movie to us; so we need to close down the current movie and install the
  695.         // new movie in its place
  696.         //
  697.         //////////
  698.         
  699.         // close the existing movie file
  700.         if ((**myWindowObject).fFileRefNum != kInvalidFileRefNum)
  701.             CloseMovieFile((**myWindowObject).fFileRefNum);
  702.         
  703.         // dispose of the existing movie controller and movie resource
  704.         if ((**myWindowObject).fController != NULL)
  705.             DisposeMovieController((**myWindowObject).fController);
  706.             
  707.         DisposeMovie(myMovie);
  708.         
  709.         // keep track of the new info
  710.         (**myWindowObject).fMovie = myNewMovie;
  711.         (**myWindowObject).fController = myMC;
  712.         (**myWindowObject).fFileFSSpec = myFile;
  713.         (**myWindowObject).fFileResID = myResID;
  714.         (**myWindowObject).fFileRefNum = myRefNum;
  715.         (**myWindowObject).fIsDirty = false;
  716.  
  717.         // make sure the movie uses the window GWorld in all situations
  718.         SetMovieGWorld(myNewMovie, (CGrafPtr)QTFrame_GetPortFromWindowReference((**myWindowObject).fWindow), NULL);
  719.  
  720.         // set the window title
  721.         QTFrame_SetWindowTitleFromFSSpec(theWindow, &myFile, true);
  722.     } else {
  723.         myErr = userCanceledErr;
  724.     }
  725.  
  726. bail:
  727.     free(myPrompt);
  728.     free(myFileName);
  729.     
  730.     return(myErr);
  731. }
  732.  
  733.  
  734. //////////
  735. //
  736. // QTFrame_UpdateMovieFile
  737. // Update the file (if any) attached to the movie.
  738. //
  739. //////////
  740.  
  741. Boolean QTFrame_UpdateMovieFile (WindowReference theWindow)
  742. {
  743.     WindowObject        myWindowObject = NULL;
  744.     Movie                 myMovie = NULL;
  745.     OSErr                myErr = noErr;
  746.     
  747.     // get the window object associated with the specified window
  748.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  749.     if (myWindowObject == NULL)
  750.         return(false);
  751.         
  752.     myMovie = (**myWindowObject).fMovie;
  753.     if (myMovie == NULL)
  754.         return(false);
  755.     
  756.     // update the current volume setting
  757.     QTUtils_UpdateMovieVolumeSetting(myMovie);
  758.     
  759.     if ((**myWindowObject).fFileRefNum == kInvalidFileRefNum)        // brand new movie, so no file attached to it
  760.         myErr = QTFrame_SaveAsMovieFile(theWindow);
  761.     else                                                            // we have an existing file; just update the movie resource
  762.         myErr = UpdateMovieResource(myMovie, (**myWindowObject).fFileRefNum, (**myWindowObject).fFileResID, NULL);
  763.     
  764.     (**myWindowObject).fIsDirty = false;
  765.  
  766.     return(myErr == noErr);
  767. }
  768.  
  769.  
  770. //////////
  771. //
  772. // QTFrame_IdleMovieWindows
  773. // Do idle-time processing on all open movie windows.
  774. //
  775. //////////
  776.  
  777. void QTFrame_IdleMovieWindows (void)
  778. {    
  779.     WindowReference            myWindow = NULL;
  780.     MovieController            myMC = NULL;
  781.     
  782.     myWindow = QTFrame_GetFrontMovieWindow();
  783.     while (myWindow != NULL) {
  784.         myMC = QTFrame_GetMCFromWindow(myWindow);
  785.         if (myMC != NULL)
  786.             MCIdle(myMC);
  787.             
  788.         QTApp_Idle(myWindow);
  789.         
  790.         myWindow = QTFrame_GetNextMovieWindow(myWindow);
  791.     }
  792. }
  793.  
  794.  
  795. //////////
  796. //
  797. // QTFrame_CloseMovieWindows
  798. // Close all open movie windows.
  799. //
  800. //////////
  801.  
  802. void QTFrame_CloseMovieWindows (void)
  803. {
  804. #if TARGET_OS_MAC    
  805.     WindowReference            myWindow = NULL;
  806.     WindowReference            myNextWindow = NULL;
  807.  
  808.     myWindow = QTFrame_GetFrontMovieWindow();
  809.     while (myWindow != NULL) {
  810.         myNextWindow = QTFrame_GetNextMovieWindow(myWindow);
  811.         QTFrame_DestroyMovieWindow(myWindow);
  812.         myWindow = myNextWindow;
  813.     }
  814. #endif
  815. #if TARGET_OS_WIN32
  816.     SendMessage(ghWnd, WM_COMMAND, (WPARAM)IDM_WINDOWCLOSEALL, 0L);
  817. #endif
  818. }
  819.  
  820.  
  821. //////////
  822. //
  823. // QTFrame_CreateWindowObject
  824. // Create a new window object associated with the specified window.
  825. //
  826. //////////
  827.  
  828. void QTFrame_CreateWindowObject (WindowReference theWindow)
  829. {
  830.     WindowObject            myWindowObject = NULL;
  831.  
  832.     if (theWindow == NULL)
  833.         return;
  834.         
  835.     // allocate space for a window object record and fill in some of its fields
  836.     myWindowObject = (WindowObject)NewHandleClear(sizeof(WindowObjectRecord));
  837.     if (myWindowObject != NULL) {
  838.         (**myWindowObject).fWindow = theWindow;
  839.         (**myWindowObject).fController = NULL;
  840.         (**myWindowObject).fObjectType = kApplicationSignature;
  841.         (**myWindowObject).fCanResizeWindow = true;
  842.         (**myWindowObject).fInstance = NULL;
  843.         (**myWindowObject).fIsDirty = false;
  844.         (**myWindowObject).fAppData = NULL;
  845.     }
  846.     
  847.     // associate myWindowObject (which may be NULL) with the window
  848. #if TARGET_OS_MAC
  849.     SetWRefCon(theWindow, (long)myWindowObject);
  850. #endif
  851. #if TARGET_OS_WIN32
  852.     SetWindowLong(theWindow, GWL_USERDATA, (LPARAM)myWindowObject);
  853.     
  854.     // associate a GrafPort with this window 
  855.     CreatePortAssociation(theWindow, NULL, 0L);
  856. #endif
  857.     
  858.     // set the current port to the new window
  859.     MacSetPort(QTFrame_GetPortFromWindowReference(theWindow));
  860. }
  861.  
  862.  
  863. //////////
  864. //
  865. // QTFrame_CloseWindowObject
  866. // Close a window object and any associated data.
  867. //
  868. //////////
  869.  
  870. void QTFrame_CloseWindowObject (WindowObject theWindowObject)
  871. {
  872.     if (theWindowObject == NULL)
  873.         return;
  874.         
  875.     // close the movie file
  876.     if ((**theWindowObject).fFileRefNum != kInvalidFileRefNum) {
  877.         CloseMovieFile((**theWindowObject).fFileRefNum);
  878.         (**theWindowObject).fFileRefNum = kInvalidFileRefNum;
  879.     }
  880.     
  881.     // dispose movie controller and movie 
  882.     if ((**theWindowObject).fController != NULL) {
  883.         MCSetActionFilterWithRefCon((**theWindowObject).fController, NULL, 0L);
  884.         DisposeMovieController((**theWindowObject).fController);
  885.         (**theWindowObject).fController = NULL;
  886.     }
  887.     
  888.     if ((**theWindowObject).fMovie != NULL) {
  889.         DisposeMovie((**theWindowObject).fMovie);
  890.         (**theWindowObject).fMovie = NULL;
  891.     }
  892.     
  893.     // close the graphics importer, if any
  894.     if ((**theWindowObject).fGraphicsImporter != NULL) {
  895.         CloseComponent((**theWindowObject).fGraphicsImporter);
  896.         (**theWindowObject).fGraphicsImporter = NULL;
  897.     }
  898.     
  899.     // do any application-specific window clean-up
  900.     QTApp_RemoveWindowObject(theWindowObject);
  901.     
  902.     DisposeHandle((Handle)theWindowObject);
  903. }
  904.  
  905.  
  906. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  907. //
  908. // Window-walking utilities.
  909. //
  910. // Use these functions to iterate through all windows or movie windows belonging to the application.
  911. //
  912. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  913.  
  914. //////////
  915. //
  916. // QTFrame_GetFrontAppWindow
  917. // Return a reference to the frontmost application window (whether or not it's a movie window).
  918. //
  919. //////////
  920.  
  921. WindowReference QTFrame_GetFrontAppWindow (void)
  922. {
  923. #if TARGET_OS_MAC
  924.     return(FrontWindow());
  925. #endif
  926. #if TARGET_OS_WIN32
  927.     return(GetWindow(ghWnd, GW_HWNDFIRST));
  928. #endif
  929. }
  930.  
  931.  
  932. //////////
  933. //
  934. // QTFrame_GetNextAppWindow
  935. // Return a reference to the next application window (whether or not it's a movie window).
  936. //
  937. //////////
  938.  
  939. WindowReference QTFrame_GetNextAppWindow (WindowReference theWindow)
  940. {
  941. #if TARGET_OS_MAC
  942.     return(theWindow == NULL ? NULL : GetNextWindow(theWindow));
  943. #endif
  944. #if TARGET_OS_WIN32
  945.     return(GetWindow(theWindow, GW_HWNDNEXT));
  946. #endif
  947. }
  948.  
  949.  
  950. //////////
  951. //
  952. // QTFrame_GetFrontMovieWindow
  953. // Return a reference to the frontmost movie window.
  954. //
  955. //////////
  956.  
  957. WindowReference QTFrame_GetFrontMovieWindow (void)
  958. {
  959.     WindowReference            myWindow;
  960.  
  961. #if TARGET_OS_MAC
  962.     myWindow = QTFrame_GetFrontAppWindow();
  963.     while ((myWindow != NULL) && (QTFrame_GetWindowObjectFromWindow(myWindow) == NULL))
  964.         myWindow = QTFrame_GetNextAppWindow(myWindow);
  965. #endif
  966.  
  967. #if TARGET_OS_WIN32
  968.     myWindow = (HWND)SendMessage(ghWndMDIClient, WM_MDIGETACTIVE, 0, 0L);
  969. #endif
  970.  
  971.     return(myWindow);
  972. }
  973.  
  974.  
  975. //////////
  976. //
  977. // QTFrame_GetNextMovieWindow
  978. // Return a reference to the next movie window.
  979. //
  980. //////////
  981.  
  982. WindowReference QTFrame_GetNextMovieWindow (WindowReference theWindow)
  983. {
  984.     WindowReference            myWindow;
  985.  
  986. #if TARGET_OS_MAC
  987.     myWindow = QTFrame_GetNextAppWindow(theWindow);
  988.     while ((myWindow != NULL) && (QTFrame_GetWindowObjectFromWindow(myWindow) == NULL))
  989.         myWindow = QTFrame_GetNextAppWindow(myWindow);
  990. #endif
  991.  
  992. #if TARGET_OS_WIN32
  993.     myWindow = GetWindow(theWindow, GW_HWNDNEXT);
  994. #endif
  995.  
  996.     return(myWindow);
  997. }
  998.  
  999.  
  1000. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  1001. //
  1002. // Data-retrieval utilities.
  1003. //
  1004. // Use the following functions to retrieve the window object, the application-specific data, or the movie
  1005. // controller that is associated with a window.
  1006. //
  1007. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  1008.  
  1009. //////////
  1010. //
  1011. // QTFrame_GetWindowObjectFromFrontWindow
  1012. // Get the window object (if any) associated with the front window.
  1013. //
  1014. //////////
  1015.  
  1016. WindowObject QTFrame_GetWindowObjectFromFrontWindow (void)
  1017. {
  1018.     return(QTFrame_GetWindowObjectFromWindow(QTFrame_GetFrontMovieWindow()));
  1019. }
  1020.  
  1021.  
  1022. //////////
  1023. //
  1024. // QTFrame_GetWindowObjectFromWindow
  1025. // Get the window object (if any) associated with the specified window.
  1026. //
  1027. //////////
  1028.  
  1029. WindowObject QTFrame_GetWindowObjectFromWindow (WindowReference theWindow)
  1030. {
  1031.     WindowObject        myWindowObject = NULL;
  1032.  
  1033.     if (!QTFrame_IsAppWindow(theWindow))
  1034.         return(NULL);
  1035.             
  1036. #if TARGET_OS_MAC
  1037.     myWindowObject = (WindowObject)GetWRefCon(theWindow);
  1038. #endif
  1039. #if TARGET_OS_WIN32
  1040.     myWindowObject = (WindowObject)GetWindowLong(theWindow, GWL_USERDATA);
  1041. #endif
  1042.  
  1043.     // make sure this is a window object
  1044.     if (!QTFrame_IsWindowObjectOurs(myWindowObject))
  1045.         return(NULL);
  1046.         
  1047.     return(myWindowObject);
  1048. }
  1049.  
  1050.  
  1051. //////////
  1052. //
  1053. // QTFrame_GetMCFromFrontWindow
  1054. // Get the movie controller (if any) associated with the front window.
  1055. //
  1056. //////////
  1057.  
  1058. MovieController QTFrame_GetMCFromFrontWindow (void)
  1059. {
  1060.     return(QTFrame_GetMCFromWindow(QTFrame_GetFrontMovieWindow()));
  1061. }
  1062.  
  1063.  
  1064. //////////
  1065. //
  1066. // QTFrame_GetMCFromWindow
  1067. // Get the movie controller (if any) associated with the specified window.
  1068. //
  1069. //////////
  1070.  
  1071. MovieController QTFrame_GetMCFromWindow (WindowReference theWindow)
  1072. {
  1073.     MovieController     myMC = NULL;
  1074.     WindowObject        myWindowObject = NULL;
  1075.         
  1076.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  1077.     if (myWindowObject != NULL)
  1078.         myMC = (**myWindowObject).fController;
  1079.         
  1080.     return(myMC);
  1081. }
  1082.  
  1083.  
  1084. //////////
  1085. //
  1086. // QTFrame_GetQTVRInstanceFromFrontWindow
  1087. // Get the QTVRInstance (if any) associated with the front window.
  1088. //
  1089. //////////
  1090.  
  1091. QTVRInstance QTFrame_GetQTVRInstanceFromFrontWindow (void)
  1092. {
  1093.     return(QTFrame_GetQTVRInstanceFromWindow(QTFrame_GetFrontMovieWindow()));
  1094. }
  1095.  
  1096.  
  1097. //////////
  1098. //
  1099. // QTFrame_GetQTVRInstanceFromWindow
  1100. // Get the QTVRInstance (if any) associated with the specified window.
  1101. //
  1102. //////////
  1103.  
  1104. QTVRInstance QTFrame_GetQTVRInstanceFromWindow (WindowReference theWindow)
  1105. {
  1106.     QTVRInstance         myInstance = NULL;
  1107.     WindowObject        myWindowObject = NULL;
  1108.     
  1109.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  1110.     if (myWindowObject != NULL)
  1111.         myInstance = (**myWindowObject).fInstance;
  1112.         
  1113.     return(myInstance);
  1114. }
  1115.  
  1116.  
  1117. //////////
  1118. //
  1119. // QTFrame_GetAppDataFromFrontWindow
  1120. // Get the application-specific data associated with the front window.
  1121. //
  1122. //////////
  1123.  
  1124. Handle QTFrame_GetAppDataFromFrontWindow (void)
  1125. {
  1126.     return(QTFrame_GetAppDataFromWindow(QTFrame_GetFrontMovieWindow()));
  1127. }
  1128.  
  1129.  
  1130. //////////
  1131. //
  1132. // QTFrame_GetAppDataFromWindow
  1133. // Get the application-specific data associated with the specified window.
  1134. //
  1135. //////////
  1136.  
  1137. Handle QTFrame_GetAppDataFromWindow (WindowReference theWindow)
  1138. {
  1139.     WindowObject        myWindowObject = NULL;
  1140.     
  1141.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  1142.     if (myWindowObject == NULL)
  1143.         return(NULL);
  1144.         
  1145.     return(QTFrame_GetAppDataFromWindowObject(myWindowObject));
  1146. }
  1147.  
  1148.  
  1149. //////////
  1150. //
  1151. // QTFrame_GetAppDataFromWindowObject
  1152. // Get the application-specific data associated with the specified window object.
  1153. //
  1154. //////////
  1155.  
  1156. Handle QTFrame_GetAppDataFromWindowObject (WindowObject theWindowObject)
  1157. {
  1158.     // make sure this is a window object belonging to our application
  1159.     if (!QTFrame_IsWindowObjectOurs(theWindowObject))
  1160.         return(NULL);
  1161.     
  1162.     return((**theWindowObject).fAppData);
  1163. }
  1164.  
  1165.  
  1166. //////////
  1167. //
  1168. // QTFrame_IsWindowObjectOurs
  1169. // Does the specified window object belong to our application?
  1170. //
  1171. //////////
  1172.  
  1173. Boolean QTFrame_IsWindowObjectOurs (WindowObject theWindowObject)
  1174. {
  1175.     OSType        myType = 0L;
  1176.  
  1177.     if ((theWindowObject == NULL) || (*theWindowObject == NULL))
  1178.         return(false);
  1179.         
  1180.     myType = (**theWindowObject).fObjectType;
  1181.     return(myType == kApplicationSignature);
  1182. }
  1183.  
  1184.  
  1185. //////////
  1186. //
  1187. // QTFrame_IsAppWindow
  1188. // Does the specified window belong to our application?
  1189. //
  1190. //////////
  1191.  
  1192. Boolean QTFrame_IsAppWindow (WindowReference theWindow)
  1193. {
  1194.     if (theWindow == NULL)
  1195.         return(false);
  1196.  
  1197. #if TARGET_OS_MAC
  1198.     return(GetWindowKind(theWindow) >= kApplicationWindowKind);
  1199. #endif
  1200. #if TARGET_OS_WIN32
  1201.     return(true);
  1202. #endif
  1203. }
  1204.  
  1205.  
  1206. //////////
  1207. //
  1208. // QTFrame_IsDocWindow
  1209. // Is the specified window a document window (having a WindowObject refcon)?
  1210. //
  1211. //////////
  1212.  
  1213. Boolean QTFrame_IsDocWindow (WindowReference theWindow)
  1214. {
  1215.     if (theWindow == NULL)
  1216.         return(false);
  1217.  
  1218. #if TARGET_OS_MAC
  1219.     return(GetWindowKind(theWindow) >= kApplicationWindowKind);
  1220. #endif
  1221. #if TARGET_OS_WIN32
  1222.     return(true);
  1223. #endif
  1224. }
  1225.  
  1226.  
  1227. //////////
  1228. //
  1229. // QTFrame_ActivateController
  1230. // Activate or deactivate the movie controller in the specified window.
  1231. //
  1232. //////////
  1233.  
  1234. void QTFrame_ActivateController (WindowReference theWindow, Boolean IsActive)
  1235. {
  1236.     WindowObject         myWindowObject = NULL;
  1237.     MovieController        myMC = NULL;
  1238.     GrafPtr                mySavedPort = NULL;
  1239.     
  1240.     if (theWindow == NULL)
  1241.         return;
  1242.     
  1243.     GetPort(&mySavedPort);
  1244.     MacSetPort(QTFrame_GetPortFromWindowReference(theWindow));
  1245.     
  1246.     // get the window object associated with the specified window
  1247.     myWindowObject = QTFrame_GetWindowObjectFromWindow(theWindow);
  1248.     if (myWindowObject != NULL) {
  1249.         myMC = (**myWindowObject).fController;
  1250.         if (myMC != NULL)
  1251.             MCActivate(myMC, QTFrame_GetWindowFromWindowReference(theWindow), IsActive);
  1252.     }
  1253.     
  1254.     MacSetPort(mySavedPort);
  1255. }
  1256.  
  1257.  
  1258. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  1259. //
  1260. // Miscellaneous utilities.
  1261. //
  1262. // Use the following functions to play beeps, manipulate menus, and do other miscellaneous things.
  1263. //
  1264. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  1265.  
  1266. //////////
  1267. //
  1268. // QTFrame_Beep
  1269. // Beep.
  1270. //
  1271. //////////
  1272.  
  1273. void QTFrame_Beep (void)
  1274. {
  1275. #if TARGET_OS_MAC
  1276.     SysBeep(30);
  1277. #endif
  1278. #if TARGET_OS_WIN32
  1279.     MessageBeep(MB_OK);
  1280. #endif
  1281. }
  1282.  
  1283.  
  1284. //////////
  1285. //
  1286. // QTFrame_SetMenuState
  1287. // Set the enabled/disabled state of a menu.
  1288. //
  1289. // On Windows, the theMenuItem parameter must be the (0-based) index in the menu bar of the
  1290. // desired pull-down menu.
  1291. //
  1292. //////////
  1293.  
  1294. void QTFrame_SetMenuState (MenuReference theMenu, UInt16 theMenuItem, short theState)
  1295. {
  1296. #if TARGET_OS_MAC
  1297. #pragma unused(theMenuItem)
  1298.     QTFrame_SetMenuItemState(theMenu, 0, theState);        // menu item == 0 means the entire menu
  1299. #endif
  1300. #if TARGET_OS_WIN32
  1301.     QTFrame_SetMenuItemState(theMenu, theMenuItem, theState | MF_BYPOSITION);
  1302. #endif
  1303. }
  1304.  
  1305.  
  1306. //////////
  1307. //
  1308. // QTFrame_SetMenuItemState
  1309. // Set the enabled/disabled state of a menu item.
  1310. //
  1311. // When running under MacOS 8.5.1, EnableMenuItem and DisableMenuItem seem to do nasty things
  1312. // to the keyboard equivalents associated with a menu; so we'll work around that problem here.
  1313. //
  1314. //////////
  1315.  
  1316. void QTFrame_SetMenuItemState (MenuReference theMenu, UInt16 theMenuItem, short theState)
  1317. {
  1318. #if TARGET_OS_MAC
  1319.     UInt8        myModifiers;
  1320.     
  1321.     // get the existing menu item modifiers
  1322.     GetMenuItemModifiers(theMenu, MENU_ITEM(theMenuItem), &myModifiers);
  1323.     
  1324.     if (theState == kEnableMenuItem)
  1325.         EnableMenuItem(theMenu, MENU_ITEM(theMenuItem));
  1326.     else
  1327.         DisableMenuItem(theMenu, MENU_ITEM(theMenuItem));
  1328.         
  1329.     // restore the previous menu item modifiers
  1330.     SetMenuItemModifiers(theMenu, MENU_ITEM(theMenuItem), myModifiers);
  1331. #endif
  1332. #if TARGET_OS_WIN32
  1333.     EnableMenuItem(theMenu, (UINT)theMenuItem, (UINT)theState);
  1334. #endif
  1335. }
  1336.  
  1337.  
  1338. //////////
  1339. //
  1340. // QTFrame_SetMenuItemLabel
  1341. // Set the label (that is, the text) of a menu item.
  1342. //
  1343. //////////
  1344.  
  1345. void QTFrame_SetMenuItemLabel (MenuReference theMenu, UInt16 theMenuItem, char *theText)
  1346. {
  1347. #if TARGET_OS_MAC
  1348.     Str255        myString;
  1349.     short        mySIndex, myTIndex;
  1350.  
  1351.     // we need to remove the '&' character while converting to a Pascal string    
  1352.     mySIndex = 1;
  1353.     for (myTIndex = 0; myTIndex < strlen(theText); myTIndex++) {
  1354.         if (theText[myTIndex] != '&') {
  1355.             myString[mySIndex] = theText[myTIndex];
  1356.             mySIndex++;
  1357.         }
  1358.     }
  1359.     
  1360.     myString[0] = mySIndex - 1;
  1361.     
  1362.     SetMenuItemText(theMenu, MENU_ITEM(theMenuItem), myString);
  1363. #endif
  1364. #if TARGET_OS_WIN32
  1365.     UINT        myState;
  1366.     
  1367.     // make sure that we preserve the current menu state
  1368.     myState = GetMenuState(theMenu, (UINT)theMenuItem, MF_BYCOMMAND);
  1369.     ModifyMenu(theMenu, (UINT)theMenuItem, MF_BYCOMMAND | MF_STRING | myState, (UINT)theMenuItem, (LPSTR)theText);
  1370. #endif
  1371. }
  1372.  
  1373.  
  1374. //////////
  1375. //
  1376. // QTFrame_SetMenuItemCheck
  1377. // Set the check mark state state of a menu item.
  1378. //
  1379. //////////
  1380.  
  1381. void QTFrame_SetMenuItemCheck (MenuReference theMenu, UInt16 theMenuItem, Boolean theState)
  1382. {
  1383. #if TARGET_OS_MAC
  1384.     MacCheckMenuItem(theMenu, MENU_ITEM(theMenuItem), theState);
  1385. #endif
  1386. #if TARGET_OS_WIN32
  1387.     CheckMenuItem(theMenu, (UINT)theMenuItem, theState ? MF_CHECKED : MF_UNCHECKED);
  1388. #endif
  1389. }
  1390.  
  1391.  
  1392. //////////
  1393. //
  1394. // QTFrame_GetPortFromWindowReference 
  1395. // Return the graphics port associated with a window reference.
  1396. //
  1397. //////////
  1398.  
  1399. GrafPtr QTFrame_GetPortFromWindowReference (WindowReference theWindow)
  1400. {
  1401. #if TARGET_OS_MAC
  1402.     return((GrafPtr)GetWindowPort(theWindow));
  1403. #endif
  1404. #if TARGET_OS_WIN32
  1405.     return(GetNativeWindowPort(theWindow));
  1406. #endif
  1407. }
  1408.  
  1409.  
  1410. //////////
  1411. //
  1412. // QTFrame_GetWindowReferenceFromPort
  1413. // Return the window reference associated with a graphics port.
  1414. //
  1415. //////////
  1416.  
  1417. WindowReference QTFrame_GetWindowReferenceFromPort (GrafPtr thePort)
  1418. {
  1419. #if TARGET_OS_MAC
  1420.     return((WindowReference)GetWindowFromPort((CGrafPtr)thePort));
  1421. #endif
  1422. #if TARGET_OS_WIN32
  1423.     return((WindowReference)GetPortNativeWindow(thePort));
  1424. #endif
  1425. }
  1426.  
  1427.  
  1428. //////////
  1429. //
  1430. // QTFrame_GetWindowFromWindowReference
  1431. // Return the Macintosh window associated with a window reference.
  1432. //
  1433. //////////
  1434.  
  1435. WindowPtr QTFrame_GetWindowFromWindowReference (WindowReference theWindow)
  1436. {
  1437. #if TARGET_OS_MAC
  1438.     return((WindowPtr)theWindow);
  1439. #endif
  1440. #if TARGET_OS_WIN32
  1441.     return((WindowPtr)GetNativeWindowPort(theWindow));
  1442. #endif
  1443. }
  1444.  
  1445.  
  1446. /////////
  1447. //
  1448. // QTFrame_GetWindowWidth
  1449. // Return the width of the specified window.
  1450. //
  1451. //////////
  1452.  
  1453. short QTFrame_GetWindowWidth (WindowReference theWindow)
  1454. {
  1455. #if TARGET_OS_MAC
  1456.     Rect        myRect = {0, 0, 0, 0};
  1457.  
  1458.     if (theWindow != NULL)
  1459.         GetWindowPortBounds(theWindow, &myRect);
  1460. #endif
  1461. #if TARGET_OS_WIN32
  1462.     RECT        myRect = {0L, 0L, 0L, 0L};
  1463.  
  1464.     if (theWindow != NULL)
  1465.         GetWindowRect(theWindow, &myRect);
  1466. #endif
  1467.  
  1468.     return((short)(myRect.right - myRect.left));
  1469. }
  1470.  
  1471.  
  1472. //////////
  1473. //
  1474. // QTFrame_SetWindowTitleFromFSSpec
  1475. // Set the title of the specified window, using the name contained in the specified FSSpec.
  1476. //
  1477. //////////
  1478.  
  1479. void QTFrame_SetWindowTitleFromFSSpec (WindowReference theWindow, FSSpecPtr theFSSpecPtr, Boolean theAddToRecentDocs)
  1480. {
  1481. #if TARGET_OS_MAC
  1482. #pragma unused(theAddToRecentDocs)
  1483.     SetWTitle(theWindow, theFSSpecPtr->name);
  1484. #endif
  1485. #if TARGET_OS_WIN32
  1486.     char    *myTempName;
  1487.     char    myWindName[MAX_PATH];
  1488.  
  1489.     // get the full pathname contained in the FSSpec (which is a Str255)
  1490.     myTempName = QTUtils_ConvertPascalToCString(theFSSpecPtr->name);
  1491.  
  1492.     // get the movie file name from the full pathname
  1493.     QTFrame_GetDisplayName(myTempName, myWindName);
  1494.  
  1495.     // set the window title
  1496.     SetWindowText(theWindow, myWindName);
  1497.     
  1498.     // add this document to the Documents list, if so instructed
  1499.     if (theAddToRecentDocs)
  1500.         SHAddToRecentDocs(SHARD_PATH, myTempName);
  1501.     
  1502.     free(myTempName);
  1503. #endif
  1504. }
  1505.  
  1506.  
  1507. //////////
  1508. //
  1509. // QTFrame_SizeWindowToMovie
  1510. // Set the window size to exactly fit the movie and controller (if visible).
  1511. //
  1512. //////////
  1513.  
  1514. void QTFrame_SizeWindowToMovie (WindowObject theWindowObject)
  1515. {
  1516.     Rect                    myMovieBounds;
  1517.     Movie                    myMovie = NULL;
  1518.     MovieController            myMC = NULL;
  1519.     GraphicsImportComponent    myImporter = NULL;
  1520.  
  1521. #if TARGET_OS_WIN32
  1522.     gWeAreSizingWindow = true;
  1523. #endif
  1524.  
  1525.     if (theWindowObject == NULL)
  1526.         goto bail;
  1527.     
  1528.     myMovie = (**theWindowObject).fMovie;
  1529.     myMC = (**theWindowObject).fController;
  1530.     myImporter = (**theWindowObject).fGraphicsImporter;
  1531.  
  1532.     if (myImporter != NULL) {
  1533.         GraphicsImportGetBoundsRect(myImporter, &myMovieBounds);
  1534.         goto gotBounds;
  1535.     }
  1536.  
  1537.     if (myMovie == NULL)
  1538.         return;
  1539.  
  1540.     GetMovieBox(myMovie, &myMovieBounds);
  1541.  
  1542.     if (myMC != NULL)
  1543.         if (MCGetVisible(myMC))
  1544.             MCGetControllerBoundsRect(myMC, &myMovieBounds);
  1545.     
  1546.     // make sure that the movie has a non-zero width;
  1547.     // a zero height is okay (for example, with a music movie with no controller bar)
  1548.     if (myMovieBounds.right - myMovieBounds.left == 0) {
  1549.         myMovieBounds.left = 0;
  1550.         myMovieBounds.right = QTFrame_GetWindowWidth((**theWindowObject).fWindow);
  1551.     }
  1552.  
  1553. gotBounds:    
  1554.     SizeWindow(QTFrame_GetWindowFromWindowReference((**theWindowObject).fWindow),
  1555.                                             myMovieBounds.right - myMovieBounds.left,
  1556.                                             myMovieBounds.bottom - myMovieBounds.top,
  1557.                                             true);
  1558.  
  1559. bail:                                        
  1560. #if TARGET_OS_WIN32
  1561.     gWeAreSizingWindow = false;
  1562. #endif
  1563.  
  1564.     return;
  1565. }
  1566.  
  1567.  
  1568. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  1569. //
  1570. // File-opening and -saving utilities.
  1571. //
  1572. // The functions are meant to provide replacements for StandardGetFilePreview and StandardPutFile, which
  1573. // are not supported under Carbon. However, Navigation Services is not (yet, at any rate) supported under
  1574. // Windows, so we still need to call through to the Standard File Package.
  1575. //
  1576. // The Navigation Services portion of this code is based selectively on the file NavigationServicesSupport.c
  1577. // by Yan Arrouye and on the developer documentation "Programming With Navigation Services 1.1". The code that
  1578. // determines which files can be opened by QuickTime is based on code by Sam Bushell in CarbonMovieEditor.c.
  1579. //
  1580. ///////////////////////////////////////////////////////////////////////////////////////////////////////////
  1581.  
  1582. //////////
  1583. //
  1584. // QTFrame_PutFile
  1585. // Save a file under the specified name. Return Boolean values indicating whether the user selected a file
  1586. // and whether the selected file is replacing an existing file.
  1587. //
  1588. //////////
  1589.  
  1590. OSErr QTFrame_PutFile (ConstStr255Param thePrompt, ConstStr255Param theFileName, FSSpecPtr theFSSpecPtr, Boolean *theIsSelected, Boolean *theIsReplacing)
  1591. {
  1592. #if TARGET_OS_WIN32
  1593.     StandardFileReply    myReply;
  1594. #endif
  1595. #if TARGET_OS_MAC
  1596.     NavReplyRecord        myReply;
  1597.     NavDialogOptions    myDialogOptions;
  1598.     NavEventUPP            myEventUPP = NewNavEventProc(QTFrame_HandleNavEvent);
  1599. #endif
  1600.     OSErr                myErr = noErr;
  1601.  
  1602.     if ((theFSSpecPtr == NULL) || (theIsSelected == NULL) || (theIsReplacing == NULL))
  1603.         return(paramErr);
  1604.     
  1605.     // deactivate any frontmost movie window
  1606.     QTFrame_ActivateController(QTFrame_GetFrontMovieWindow(), false);
  1607.  
  1608.     // assume we are not replacing an existing file
  1609.     *theIsReplacing = false;
  1610.     
  1611. #if TARGET_OS_WIN32
  1612.     StandardPutFile(thePrompt, theFileName, &myReply);
  1613.     *theFSSpecPtr = myReply.sfFile;
  1614.     *theIsSelected = myReply.sfGood;
  1615.     if (myReply.sfGood)
  1616.         *theIsReplacing = myReply.sfReplacing;
  1617. #endif
  1618.  
  1619. #if TARGET_OS_MAC
  1620.     // specify the options for the dialog box
  1621.     NavGetDefaultDialogOptions(&myDialogOptions);
  1622.     myDialogOptions.dialogOptionFlags += kNavNoTypePopup;
  1623.     myDialogOptions.dialogOptionFlags += kNavDontAutoTranslate;
  1624.     BlockMoveData(theFileName, myDialogOptions.savedFileName, theFileName[0] + 1);
  1625.     BlockMoveData(gAppName, myDialogOptions.clientName, gAppName[0] + 1);
  1626.     BlockMoveData(thePrompt, myDialogOptions.message, thePrompt[0] + 1);
  1627.     
  1628.     // prompt the user for a file
  1629.     myErr = NavPutFile(NULL, &myReply, &myDialogOptions, myEventUPP, MovieFileType, sigMoviePlayer, NULL);
  1630.     if ((myErr == noErr) && myReply.validRecord) {
  1631.         AEKeyword        myKeyword;
  1632.         DescType        myActualType;
  1633.         Size            myActualSize = 0;
  1634.         
  1635.         // get the FSSpec for the selected file
  1636.         if (theFSSpecPtr != NULL)
  1637.             myErr = AEGetNthPtr(&(myReply.selection), 1, typeFSS, &myKeyword, &myActualType, theFSSpecPtr, sizeof(FSSpec), &myActualSize);
  1638.  
  1639.         NavDisposeReply(&myReply);
  1640.     }
  1641.         
  1642.     *theIsSelected = myReply.validRecord;
  1643.     if (myReply.validRecord)
  1644.         *theIsReplacing = myReply.replacing;
  1645.  
  1646.     DisposeNavEventUPP(myEventUPP);
  1647. #endif
  1648.  
  1649.     return(myErr);
  1650. }
  1651.     
  1652.  
  1653. //////////
  1654. //
  1655. // QTFrame_GetOneFileWithPreview
  1656. // Display the appropriate file-opening dialog box, with an optional QuickTime preview pane. If the user
  1657. // selects a file, return information about it using the theFSSpecPtr parameter.
  1658. //
  1659. // Note that both StandardGetFilePreview and NavGetFile use the function specified by theFilterProc as a
  1660. // file filter. This framework always passes NULL in the theFilterProc parameter. If you use this function
  1661. // in your own code, keep in mind that on Windows the function specifier must be of type FileFilterUPP and 
  1662. // on Macintosh it must be of type NavObjectFilterUPP. (You can use the QTFrame_GetFileFilterUPP to create
  1663. // a function specifier of the appropriate type.) Also keep in mind that Navigation Services expects a file 
  1664. // filter function to return true if a file is to be displayed, while the Standard File Package expects the
  1665. // filter to return false if a file is to be displayed.
  1666. //
  1667. //////////
  1668.  
  1669. OSErr QTFrame_GetOneFileWithPreview (short theNumTypes, QTFrameTypeListPtr theTypeList, FSSpecPtr theFSSpecPtr, void *theFilterProc)
  1670. {
  1671. #if TARGET_OS_WIN32
  1672.     StandardFileReply    myReply;
  1673. #endif
  1674. #if TARGET_OS_MAC
  1675.     NavReplyRecord        myReply;
  1676.     NavDialogOptions    myDialogOptions;
  1677.     NavTypeListHandle    myOpenList = NULL;
  1678.     NavEventUPP            myEventUPP = NewNavEventProc(QTFrame_HandleNavEvent);
  1679. #endif
  1680.     OSErr                myErr = noErr;
  1681.     
  1682.     if (theFSSpecPtr == NULL)
  1683.         return(paramErr);
  1684.     
  1685.     // deactivate any frontmost movie window
  1686.     QTFrame_ActivateController(QTFrame_GetFrontMovieWindow(), false);
  1687.  
  1688. #if TARGET_OS_WIN32
  1689.     // prompt the user for a file
  1690.     StandardGetFilePreview((FileFilterUPP)theFilterProc, theNumTypes, (ConstSFTypeListPtr)theTypeList, &myReply);
  1691.     if (!myReply.sfGood)
  1692.         return(userCanceledErr);
  1693.     
  1694.     // make an FSSpec record
  1695.     myErr = FSMakeFSSpec(myReply.sfFile.vRefNum, myReply.sfFile.parID, myReply.sfFile.name, theFSSpecPtr);
  1696. #endif
  1697.  
  1698. #if TARGET_OS_MAC
  1699.     // specify the options for the dialog box
  1700.     NavGetDefaultDialogOptions(&myDialogOptions);
  1701.     myDialogOptions.dialogOptionFlags -= kNavNoTypePopup;
  1702.     myDialogOptions.dialogOptionFlags -= kNavAllowMultipleFiles;
  1703.     BlockMoveData(gAppName, myDialogOptions.clientName, gAppName[0] + 1);
  1704.     
  1705.     // create a handle to an 'open' resource
  1706.     myOpenList = (NavTypeListHandle)QTFrame_CreateOpenHandle(kApplicationSignature, theNumTypes, theTypeList);
  1707.     if (myOpenList != NULL)
  1708.         HLock((Handle)myOpenList);
  1709.     
  1710.     // prompt the user for a file
  1711.     myErr = NavGetFile(NULL, &myReply, &myDialogOptions, myEventUPP, NULL, (NavObjectFilterUPP)theFilterProc, myOpenList, NULL);
  1712.     if ((myErr == noErr) && myReply.validRecord) {
  1713.         AEKeyword        myKeyword;
  1714.         DescType        myActualType;
  1715.         Size            myActualSize = 0;
  1716.         
  1717.         // get the FSSpec for the selected file
  1718.         if (theFSSpecPtr != NULL)
  1719.             myErr = AEGetNthPtr(&(myReply.selection), 1, typeFSS, &myKeyword, &myActualType, theFSSpecPtr, sizeof(FSSpec), &myActualSize);
  1720.  
  1721.         NavDisposeReply(&myReply);
  1722.     }
  1723.     
  1724.     if (myOpenList != NULL) {
  1725.         HUnlock((Handle)myOpenList);
  1726.         DisposeHandle((Handle)myOpenList);
  1727.     }
  1728.     
  1729.     DisposeNavEventUPP(myEventUPP);
  1730. #endif
  1731.  
  1732.     return(myErr);
  1733. }
  1734.  
  1735.  
  1736. //////////
  1737. //
  1738. // QTFrame_HandleNavEvent
  1739. // A callback procedure that handles events while a Navigation Service dialog box is displayed.
  1740. //
  1741. //////////
  1742.  
  1743. PASCAL_RTN void QTFrame_HandleNavEvent (NavEventCallbackMessage theCallBackSelector, NavCBRecPtr theCallBackParms, void *theCallBackUD)
  1744. {
  1745. #pragma unused(theCallBackUD)
  1746.     WindowReference        myWindow = NULL;    
  1747.     
  1748.     if (theCallBackSelector == kNavCBEvent) {
  1749.         switch (theCallBackParms->eventData.eventDataParms.event->what) {
  1750.             case updateEvt:
  1751. #if TARGET_OS_MAC
  1752.                 QTFrame_HandleEvent(theCallBackParms->eventData.eventDataParms.event);
  1753. #endif
  1754.                 break;
  1755.             case nullEvent:
  1756.                 QTFrame_IdleMovieWindows();
  1757.                 break;
  1758.         }
  1759.     }
  1760. }
  1761.  
  1762.  
  1763. //////////
  1764. //
  1765. // QTFrame_CreateOpenHandle
  1766. // Return a handle to a dynamically-created 'open' resource.
  1767. //
  1768. //////////
  1769.  
  1770. Handle QTFrame_CreateOpenHandle (OSType theApplicationSignature, short theNumTypes, QTFrameTypeListPtr theTypeList)
  1771. {
  1772.     Handle            myHandle = NULL;
  1773.     
  1774.     if (theTypeList == NULL)
  1775.         return(myHandle);
  1776.     
  1777.     if (theNumTypes > 0) {
  1778.         myHandle = NewHandle(sizeof(NavTypeList) + (theNumTypes * sizeof(OSType)));
  1779.         if (myHandle != NULL) {
  1780.             NavTypeListHandle     myOpenResHandle    = (NavTypeListHandle)myHandle;
  1781.             
  1782.             (*myOpenResHandle)->componentSignature = theApplicationSignature;
  1783.             (*myOpenResHandle)->osTypeCount = theNumTypes;
  1784.             BlockMoveData(theTypeList, (*myOpenResHandle)->osType, theNumTypes * sizeof(OSType));
  1785.         }
  1786.     }
  1787.     
  1788.     return(myHandle);
  1789. }
  1790.  
  1791.  
  1792. //////////
  1793. //
  1794. // QTFrame_GetFileFilterUPP
  1795. // Return a UPP for the specified file-selection filter function.
  1796. //
  1797. // The caller is responsible for disposing of the UPP returned by this function (by calling DisposeRoutineDescriptor).
  1798. //
  1799. //////////
  1800.  
  1801. QTFrameFileFilterUPP QTFrame_GetFileFilterUPP (ProcPtr theFileFilterProc)
  1802. {
  1803. #if TARGET_OS_MAC
  1804.     return(NewNavObjectFilterUPP((NavObjectFilterProcPtr)theFileFilterProc));
  1805. #endif
  1806. #if TARGET_OS_WIN32
  1807.     return(NewFileFilterProc(theFileFilterProc));
  1808. #endif
  1809. }
  1810.  
  1811.  
  1812. //////////
  1813. //
  1814. // QTFrame_FilterFiles
  1815. // Filter files for a file-opening dialog box.
  1816. //
  1817. // The default behavior here is to accept all files that can be opened by QuickTime, whether directly
  1818. // or using a movie importer or a graphics importer.
  1819. //
  1820. //////////
  1821.  
  1822. #if TARGET_OS_MAC
  1823. PASCAL_RTN Boolean QTFrame_FilterFiles (AEDesc *theItem, void *theInfo, void *theCallBackUD, NavFilterModes theFilterMode)
  1824. {
  1825. #pragma unused(theCallBackUD, theFilterMode)
  1826.     NavFileOrFolderInfo        *myInfo = (NavFileOrFolderInfo *)theInfo;
  1827.     
  1828.     if (gValidFileTypes == NULL)
  1829.         QTFrame_BuildFileTypeList();
  1830.  
  1831.     if (theItem->descriptorType == typeFSS) {
  1832.         if (!myInfo->isFolder) {
  1833.             OSType            myType = myInfo->fileAndFolder.fileInfo.finderInfo.fdType;
  1834.             short            myCount;
  1835.             short            myIndex;
  1836.             
  1837.             // see whether the file type is in the list of file types that our application can open 
  1838.             myCount = GetPtrSize((Ptr)gValidFileTypes) / sizeof(OSType);
  1839.             for (myIndex = 0; myIndex < myCount; myIndex++)
  1840.                 if (myType == gValidFileTypes[myIndex])
  1841.                     return(true);
  1842.  
  1843.             // if we got to here, it's a file we cannot open
  1844.             return(false);        
  1845.         }
  1846.     }
  1847.     
  1848.     // if we got to here, it's a folder or non-HFS object
  1849.     return(true);
  1850. }
  1851. #endif
  1852. #if TARGET_OS_WIN32
  1853. PASCAL_RTN Boolean QTFrame_FilterFiles (CInfoPBPtr thePBPtr)
  1854. {
  1855. #pragma unused(thePBPtr)
  1856.     return(false);
  1857. }
  1858. #endif
  1859.  
  1860.  
  1861. //////////
  1862. //
  1863. // QTFrame_BuildFileTypeList
  1864. // Build a list of file types that QuickTime can open.
  1865. //
  1866. //////////
  1867.  
  1868. OSErr QTFrame_BuildFileTypeList (void)
  1869. {
  1870.     long        myIndex = 0;
  1871.     OSErr        myErr = noErr;
  1872.  
  1873.     // if we've already built the list, just return
  1874.     if (gValidFileTypes != NULL)
  1875.         return(myErr);
  1876.     
  1877.     // allocate a block of memory to hold a preset number of file types; we'll resize this block
  1878.     // while building the list if we need more room; we always resize it after building the list,
  1879.     // to truncate it to the exact size required
  1880.     gValidFileTypes = (OSType *)NewPtrClear(sizeof(OSType) * kDefaultFileTypeCount);
  1881.     if (gValidFileTypes == NULL)
  1882.         return(memFullErr);
  1883.     
  1884.     // we can open any files of type kQTFileTypeMovie
  1885.     gValidFileTypes[myIndex++] = kQTFileTypeMovie;
  1886.     
  1887.     // we can open any files for which QuickTime supplies a movie importer component
  1888.     QTFrame_AddComponentFileTypes(MovieImportType, &myIndex);
  1889.     
  1890.     // we can open any files for which QuickTime supplies a graphics importer component
  1891.     QTFrame_AddComponentFileTypes(GraphicsImporterComponentType, &myIndex);
  1892.  
  1893.     // resize the pointer to hold the exact number of valid file types
  1894.     SetPtrSize((Ptr)gValidFileTypes, myIndex * sizeof(OSType));
  1895.     myErr = MemError();
  1896.     
  1897.     return(myErr);
  1898. }
  1899.  
  1900.  
  1901. //////////
  1902. //
  1903. // QTFrame_AddComponentFileTypes
  1904. // Add all subtypes of the specified component type to the global list of file types.
  1905. //
  1906. //////////
  1907.  
  1908. static void QTFrame_AddComponentFileTypes (OSType theComponentType, long *theNextIndex)
  1909. {
  1910.     ComponentDescription        myFindCompDesc = {0, 0, 0, 0, 0};
  1911.     ComponentDescription        myInfoCompDesc = {0, 0, 0, 0, 0};
  1912.     Component                    myComponent = NULL;
  1913.  
  1914.     myFindCompDesc.componentType = theComponentType;
  1915.     myFindCompDesc.componentFlags = 0;
  1916.     myFindCompDesc.componentFlagsMask = movieImportSubTypeIsFileExtension;
  1917.  
  1918.     myComponent = FindNextComponent(myComponent, &myFindCompDesc);
  1919.     while (myComponent != NULL) {
  1920.         GetComponentInfo(myComponent, &myInfoCompDesc, NULL, NULL, NULL);
  1921.         gValidFileTypes[*theNextIndex] = myInfoCompDesc.componentSubType;
  1922.         *theNextIndex += 1;
  1923.         
  1924.         // resize the block of file types, if we are about to reach the limit
  1925.         if (*theNextIndex == GetPtrSize((Ptr)gValidFileTypes) / (long)sizeof(OSType)) {
  1926.             SetPtrSize((Ptr)gValidFileTypes, GetPtrSize((Ptr)gValidFileTypes) + (kDefaultFileTypeCount * sizeof(OSType)));
  1927.             if (MemError() != noErr)
  1928.                 return;
  1929.         }
  1930.         
  1931.         myComponent = FindNextComponent(myComponent, &myFindCompDesc);
  1932.     }
  1933. }
  1934.  
  1935.  
  1936. #if TARGET_OS_WIN32
  1937. //////////
  1938. //
  1939. // QTFrame_ConvertMacToWinRect
  1940. // Convert a Macintosh Rect structure into a Windows RECT structure.
  1941. //
  1942. //////////
  1943.  
  1944. void QTFrame_ConvertMacToWinRect (Rect *theMacRect, RECT *theWinRect)
  1945. {
  1946.     theWinRect->top = (long)theMacRect->top;
  1947.     theWinRect->left = (long)theMacRect->left;
  1948.     theWinRect->bottom = (long)theMacRect->bottom;
  1949.     theWinRect->right = (long)theMacRect->right;
  1950. }
  1951.  
  1952.  
  1953. //////////
  1954. //
  1955. // QTFrame_ConvertWinToMacRect
  1956. // Convert a Windows RECT structure into a Macintosh Rect structure.
  1957. //
  1958. //////////
  1959.  
  1960. void QTFrame_ConvertWinToMacRect (RECT *theWinRect, Rect *theMacRect)
  1961. {
  1962.     theMacRect->top = (short)theWinRect->top;
  1963.     theMacRect->left = (short)theWinRect->left;
  1964.     theMacRect->bottom = (short)theWinRect->bottom;
  1965.     theMacRect->right = (short)theWinRect->right;
  1966. }
  1967. #endif
  1968.